home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 607 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: overriding functions a la Stroustrup allow
  5. Date: 01 Mar 1996 09:04:37 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4h78mr$alj@engnews1.Eng.Sun.COM>
  9. References: <4h4hmr$41o@news.rwth-aachen.de>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 1 Mar 1996 16:30:19 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMTcuOUy4NqrwXLNJAQEf+wIApCaE1qAXm+WcGZjTXeHl+4MW3In5bZ8F
  15.     o46RNVQZzwMVSQgvlHxJJfYLrnvoVT0YbDq/qkRTVn/Z1yixORM+eg==
  16.     =bCxY
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article 41o@news.rwth-aachen.de, fischer@Informatik.RWTH-Aachen.DE (Rainer Fischer) writes:
  20. >In "Bjarne Stroustrup, The C++ programming language (german translation)"
  21. >I found an example, which looks like this:
  22. >
  23. >struct base {
  24. >  base *next;
  25. >  static base *list;
  26. >
  27. >  base() {next = list; list = this};
  28. >
  29. >  virtual void function() = 0;
  30. >  // ...
  31. >};
  32. >
  33. >class derived : public base {
  34. >  // ...
  35. >public:
  36. >  void function();
  37. >  // ...
  38. >};
  39. >
  40. >
  41. >Two questions:
  42. >
  43. >1)  Does function() in class derived really override function() in base?
  44.  
  45. Yes.
  46.  
  47. >    Does the declaration in derived really say that function is not pure
  48. >    virtual and not virtual at all? 
  49.  
  50. Yes, No. Since it has the same signature as a base-class virtual function,
  51. it overrides that function and is virtual. That is, the derived-class
  52. version is virtual whether you declare it virtual explicitly or not. It is
  53. not pure virtual because it does not have "=0" as part of the declaration.
  54.  
  55. >    I get a linker error-message, when I
  56. >    use such a construction without defining the overriding function, but
  57. >    neither a compiler error nor a warning. Is this correct?
  58.  
  59. Yes. If you declare a non-pure virtual function, most implementations
  60. require you to define it whether you call the function or not. The lack
  61. of a definition is typically found during (one of) the linking phase(s).
  62.  
  63.  
  64. >2)  What happens, when the very first object is created with a class
  65. >    derived from base? The constructor of base assignes list to next, but
  66. >    list is not yet initialized; so rubbish may be assigned to next. Is
  67. >    there no need to initialize list first, e.g. base *base::list = 0; some-
  68. >    where outside of base?
  69.  
  70. A static data member of a class requires a separate definition outside
  71. the class. (The declaration inside the class is not a definition.)
  72.  
  73. ---
  74. Steve Clamage, stephen.clamage@eng.sun.com
  75. ---
  76. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  77.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  78.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  79.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  80.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  81. ]
  82.